3 PRINT CHR$(4);"PR#3"

5 ONERR GOTO 6

6 INVERSE:VTAB 1:HTAB 28:PRINT"RANDOM MAZE TOOL FOR GM-MODE":VTAB 23:HTAB 1:PRINT"                                                                               ":VTAB 23:HTAB 1:INPUT"INPUT A NUMBER BETWEEN 1 TO 99999 : ";RR:NORMAL
7 IF RR<1 OR RR>99999 THEN 6

8 HOME


9 GOSUB 20000

10 HOME

30 DIM B(40,40)
32 DIM C(1510)

33 DIM M1(2000)

35 X1=22:Y1=20:X2=22:Y2=20:BB=0


38 HOME:GR:ONERR GOTO 23000



40 COLOR=0:PLOT 20,20
45 COLOR=15:PLOT 20,20
50 COLOR=1:PLOT 22,20
52 VTAB 21:HTAB 6:PRINT"Y":VTAB 21:HTAB 10:PRINT"I":VTAB 21:HTAB 15:PRINT"R - RUN":VTAB 21:HTAB 25:PRINT"S - SAVE MAZE":VTAB 21:HTAB 66:PRINT" BLOCK :    0 "
54 VTAB 22:HTAB 5:PRINT"G H":VTAB 22:HTAB 9:PRINT"J K":VTAB 22:HTAB 25:PRINT"L - LOAD MAZE":VTAB 22:HTAB 42:PRINT"X - CATALOG":VTAB 22:HTAB 55:PRINT"O - HELP":VTAB 22:HTAB 66:PRINT"  STEP :    0 "
56 VTAB 23:HTAB 6:PRINT"B":VTAB 23:HTAB 10:PRINT"M":VTAB 23:HTAB 15:PRINT"Q - QUIT":VTAB 23:HTAB 25:PRINT"C - CLEAR SCN":VTAB 23:HTAB 42:PRINT"A - RANDOM MAZE":VTAB 23:HTAB 66:PRINT"RESTEP :    0 "

58 REM

59 GOSUB 1200

60 NO=0:R1=0
62 COLOR=15:PLOT 20,20:GET A$:GOSUB 60000

65 IF A$="Q" THEN 8000


66 IF A$=CHR$(25) THEN X2=X1:Y2=Y1-1:GOSUB 1000:GOSUB 29000:X1=X2:Y1=Y2
67 IF A$=CHR$(7) THEN X2=X1-1:Y2=Y1:GOSUB 1000:GOSUB 29000:X1=X2:Y1=Y2
68 IF A$=CHR$(8) THEN X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0:GOSUB 1200:X1=X2:Y1=Y2

160 IF A$="R" THEN 300
170 IF A$="S" THEN 15000
180 IF A$="L" THEN 15100
182 IF A$="C" THEN 15500
184 IF A$="X" THEN 15800
186 IF A$="O" THEN 18000

190 IF A$="A" THEN 9000


200 GOTO 60


300 X4=20:Y4=20:I1=1:S1=0:H2=0
305 VTAB 21:HTAB 44:PRINT"                ":VTAB 22:HTAB 75:PRINT"   0":VTAB 23:HTAB 75:PRINT"   0"
310 IF B(20,20)=1 THEN B(20,20)=0:COLOR=15:PLOT 20,20:BB=BB-1:GOSUB 1200

312 REM IF B(V8,V9)=1 AND G1>0 THEN B(V8,V9)=0:VTAB V8:HTAB V9:PRINT"T":BB=BB-1:GOSUB 1200 

314 IF B(X4,Y4+1)=1 AND B(X4+1,Y4+1)=1 AND B(X4+1,Y4)=1 AND B(X4+1,Y4-1)=1 AND B(X4,Y4-1)=1 AND B(X4-1,Y4-1)=1 AND B(X4-1,Y4)=1 AND B(X4-1,Y4+1)=1 THEN INVERSE:VTAB 21:HTAB 47:PRINT"NO EXIT":NORMAL:GOTO 60


315 COLOR=15:PLOT X4,Y4
320 X5=X4:Y5=Y4

330 IF B(X4+1,Y4-1)=0 THEN XX=X4+1:YY=Y4-1:Q=5:F1=1:GOTO 530
340 IF B(X4+1,Y4)=0 THEN XX=X4+1:YY=Y4:Q=4:F1=2:GOTO 530
350 IF B(X4+1,Y4+1)=0 THEN XX=X4+1:YY=Y4+1:Q=6:F1=3:GOTO 530
360 IF B(X4,Y4+1)=0 THEN XX=X4:YY=Y4+1:Q=3:F1=4:GOTO 530
370 IF B(X4-1,Y4+1)=0 THEN XX=X4-1:YY=Y4+1:Q=7:F1=5:GOTO 530
380 IF B(X4-1,Y4)=0 THEN XX=X4-1:YY=Y4:Q=2:F1=6:GOTO 530
390 IF B(X4-1,Y4-1)=0 THEN XX=X4-1:YY=Y4-1:Q=8:F1=7:GOTO 530
395 IF B(X4,Y4-1)=0 THEN XX=X4:YY=Y4-1:Q=1:F1=8:GOTO 530

400 I1=I1-1:IF I1<1 THEN I1=1
410 A7=C(I1):C(I1)=23:H2=H2+1:N1=23:N2=78:GOSUB 900

420 IF A7=1 THEN YY=Y4+1:XX=X4
430 IF A7=4 THEN XX=X4-1:YY=Y4
440 IF A7=3 THEN YY=Y4-1:XX=X4
450 IF A7=2 THEN XX=X4+1:YY=Y4
460 IF A7=5 THEN XX=X4-1:YY=Y4+1
470 IF A7=6 THEN XX=X4-1:YY=Y4-1
480 IF A7=7 THEN XX=X4+1:YY=Y4-1
490 IF A7=8 THEN XX=X4+1:YY=Y4+1

500 GOTO 550
530 IF B(XX,YY)=2 THEN XX=X4:YY=Y4:ON F1 GOTO 340,350,360,370,380,390,395,400
540 C(I1)=Q:I1=I1+1

550 COLOR=0:PLOT X4,Y4:B(XX,YY)=2 

560 IF XX>39 OR XX<1 OR YY>39 OR YY<1 THEN COLOR=0:PLOT X5,Y5:S1=0:H2=0:GOTO 650
570 X4=XX:Y4=YY:COLOR=15:PLOT X4,Y4:COLOR=0:PLOT X5,Y5
575 IF XX=20 AND YY=20 THEN R1=R1+1 
577 IF R1>8 THEN R1=0:NO=1:INVERSE:VTAB 21:HTAB 44:PRINT"NO EXIT":NORMAL:GOTO 650

580 S1=S1+1:N1=22:N2=78
590 IF S1>9 THEN N2=N2-1
600 IF S1>99 THEN N2=N2-1
610 IF S1>999 THEN N2=N2-1
620 VTAB N1:HTAB N2: PRINT S1
640 GOTO 315

650 FLASH:VTAB 21:HTAB 57:PRINT"WAITING":NORMAL

660 FOR I=0 TO 40
670 FOR J=0 TO 40
680 IF B(I,J)<>1 THEN B(I,J)=0
690 NEXT J
700 NEXT I

705 VTAB 21:HTAB 57:PRINT"       "

710 IF NO=1 THEN NO=0:GOTO 60

720 INVERSE:VTAB 21:HTAB 44:PRINT"SHORTCUT":NORMAL

730 X7=20:Y7=20:I2=1:CUT=0

740 IF C(I2)=5 THEN X8=X7+1:Y8=Y7-1
750 IF C(I2)=4 THEN X8=X7+1:Y8=Y7
760 IF C(I2)=6 THEN X8=X7+1:Y8=Y7+1
770 IF C(I2)=3 THEN X8=X7:Y8=Y7+1
780 IF C(I2)=7 THEN X8=X7-1:Y8=Y7+1
790 IF C(I2)=2 THEN X8=X7-1:Y8=Y7
792 IF C(I2)=8 THEN X8=X7-1:Y8=Y7-1 
794 IF C(I2)=1 THEN X8=X7:Y8=Y7-1

796 IF X8>39 OR X8<1 OR Y8>39 OR Y8<1 THEN COLOR=0:PLOT X7,Y7:GOTO 60

800 COLOR=15:PLOT X8,Y8:COLOR=0:PLOT X7,Y7:CUT=CUT+1:VTAB 21:HTAB 54:PRINT CUT:X7=X8:Y7=Y8
810 I2=I2+1
880 GOTO 740



900 IF H2>9 THEN N2=N2-1
910 IF H2>99 THEN N2=N2-1
920 IF H2>999 THEN N2=N2-1
930 VTAB N1:HTAB N2: PRINT H2
940 RETURN

1000 IF X2<1 THEN X2=39
1010 IF X2>39 THEN X2=1
1020 IF Y2<1 THEN Y2=39
1030 IF Y2>39 THEN Y2=1
1040 RETURN

1100 IF B(X1,Y1)=0 THEN BB=BB+1
1110 RETURN 

1150 IF B(X1,Y1)=1 THEN BB=BB-1
1160 RETURN

1200 IF BB<0 THEN BB=0
1210 IF BB<10 AND BB>-1 THEN NN1=78
1220 IF BB<100 AND BB>9 THEN NN1=77
1230 IF BB<1000 AND BB>99 THEN NN1=76
1240 IF BB<10000 AND BB>999 THEN NN1=75
1250 VTAB 21:HTAB 75:PRINT"    "
1260 VTAB 21:HTAB NN1:PRINT BB
1270 RETURN


1400 N1=22:N2=78
1410 IF S1>9 THEN N2=N2-1
1420 IF S1>99 THEN N2=N2-1
1430 IF S1>999 THEN N2=N2-1
1440 VTAB N1:HTAB N2: PRINT S1
1450 RETURN









8000 TEXT:HOME:END


9000 INVERSE:VTAB 21:HTAB 57:PRINT"WORKING":NORMAL:VTAB 21:HTAB 44:PRINT"             "

9001 NORMAL:VTAB 21:HTAB 75:PRINT"    ":VTAB 22:HTAB 75:PRINT"    ":VTAB 23:HTAB 75:PRINT"    ":BB=0:GOSUB 1200:S1=0:GOSUB 1400:N1=23:N2=78:H2=0:GOSUB 900

9002 FOR I=0 TO 40
9010 FOR J=0 TO 40
9030 B(I,J)=0
9040 NEXT J
9050 NEXT I

9100 FOR I=1 TO 39
9110 FOR J=1 TO 39
9115 IF I=20 AND J=20 THEN 9130
9120 COLOR=1:PLOT I,J:B(I,J)=1:BB=BB+1:GOSUB 1200
9130 NEXT J
9140 NEXT I

9150 FOR I=1 TO RR
9160 TE=RND(RR)
9170 NEXT I

9180 RR=TE

9400 P1=0:P2=0:P3=0:P4=0:P5=0
9410 M1(1)=2019:M1(2)=2021:M1(3)=1920:M1(4)=2120:P1=4
9415 REM

9500 P3=0
9510 IF P5>30000 THEN P4=1:GOSUB 10000:COLOR=6:PLOT X1,Y1:NORMAL:VTAB 21:HTAB 57:PRINT"       ":P4=0:GOTO 60
9520 P5=P5+1
9550 REM

9600 S9=INT(RND(RR)*P1+1)

9610 XC=INT(M1(S9)/100):YC=M1(S9)-XC*100
9611 IF XC<1 OR XC>39 OR YC<1 OR YC>39 THEN 9500 


9612 IF B(XC-1,YC)=0 THEN P3=P3+1:T1=1
9613 IF B(XC+1,YC)=0 THEN P3=P3+1:T2=1
9614 IF B(XC,YC-1)=0 THEN P3=P3+1:T3=1
9615 IF B(XC,YC+1)=0 THEN P3=P3+1:T4=1

9618 IF P3>1 THEN 9500

9620 T5=1:COLOR=0:PLOT XC,YC:B(XC,YC)=0:BB=BB-1:GOSUB 1200

9622 FOR J=S9 TO P1
9623 M1(J)=M1(J+1)
9624 NEXT J

9626 FOR K=P1 TO 2000:M1(K)=0:NEXT K

9627 P1=P1-1

9630 IF B(XC-1,YC)=1 THEN P1=P1+1:M1(P1)=(XC-1)*100+YC
9640 IF B(XC+1,YC)=1 THEN P1=P1+1:M1(P1)=(XC+1)*100+YC
9650 IF B(XC,YC-1)=1 THEN P1=P1+1:M1(P1)=(XC)*100+YC-1
9660 IF B(XC,YC+1)=1 THEN P1=P1+1:M1(P1)=(XC)*100+YC+1

9870 REM

9900 GOTO 9500

10000 REM
10010 S2=INT(RND(RR)*4+1)

10100 IF S2=1 THEN XB=1:YB=INT(RND(RR)*39+1):GOTO 11040
10110 IF S2=2 THEN XB=39:YB=INT(RND(RR)*39+1):GOTO 11040
10120 IF S2=3 THEN YB=1:XB=INT(RND(RR)*39+1):GOTO 11040
10130 IF S2=4 THEN YB=39:XB=INT(RND(RR)*39+1):GOTO 11040

10132 GOTO 10000

11040 COLOR=0:PLOT XB,YB:B(XB,YB)=0:BB=BB-1:GOSUB 1200

11041 RETURN


15000 INVERSE:VTAB 21:HTAB 40:PRINT"FILENAME : ":NORMAL:VTAB 21:HTAB 51:INPUT F$
15002 GOSUB 22000:GOSUB 1200

15004 IF F$=CHR$(43) THEN GOSUB 22000:GOSUB 1200:GOTO 60

15005 INVERSE:VTAB 21:HTAB 57:PRINT"SAVING":NORMAL

15006 IF LEN(F$) > 24 THEN GOSUB 22000:GOSUB 1200:GOTO 15000

15009 ONERR GOTO 23000

15010 PRINT CHR$(4);"OPEN";F$
15020 PRINT CHR$(4);"WRITE";F$ 
15030 FOR I=1 TO 39
15040 FOR J=1 TO 39
15050 PRINT B(I,J)
15060 NEXT J
15070 NEXT I
15080 PRINT CHR$(4);"CLOSE";F$

15081 PRINT CHR$(4);"OPEN";F$+".INDEX"
15082 PRINT CHR$(4);"WRITE";F$+".INDEX"
15083 PRINT X1:PRINT Y1
15084 PRINT CHR$(4);"CLOSE";F$+".INDEX"

15086 PRINT CHR$(4);"OPEN";F$+".BITMAP"
15088 PRINT CHR$(4);"WRITE";F$+".BITMAP" 
15090 FOR I=1 TO 39
15092 FOR J=1 TO 39
15093 PRINT B(I,J);
15094 NEXT J
15095 PRINT
15096 NEXT I
15097 PRINT CHR$(4);"CLOSE";F$+".BITMAP"

15098 VTAB 21:HTAB 57:PRINT"      "
15099 GOTO 60




15100 INVERSE:VTAB 21:HTAB 40:PRINT"FILENAME : ":NORMAL:VTAB 21:HTAB 51:PRINT"        ":VTAB 21:HTAB 51:INPUT F$
15102 GOSUB 22000:GOSUB 1200

15104 IF F$=CHR$(43) THEN GOSUB 22000:GOSUB 1200:GOTO 60

15105 ONERR GOTO 23000

15107 INVERSE:VTAB 21:HTAB 57:PRINT"LOADING":NORMAL

15108 PRINT:PRINT

15110 REM PRINT CHR$(4);"OPEN";F$
15120 PRINT CHR$(4);"READ";F$ 
15130 FOR I=1 TO 39
15140 FOR J=1 TO 39
15150 INPUT B(I,J)
15160 NEXT J
15170 NEXT I

15180 PRINT CHR$(4);"CLOSE";F$

15181 REM PRINT CHR$(4);"OPEN";F$+".INDEX"
15182 PRINT CHR$(4);"READ";F$+".INDEX"
15183 INPUT X1:INPUT Y1
15184 PRINT CHR$(4);"CLOSE";F$+".INDEX"

15186 VTAB 21:HTAB 57:PRINT"       "

15187 GOSUB 15200
15188 COLOR=6:PLOT X1,Y1

15189 VTAB 22:HTAB 75:PRINT"   0":VTAB 23:HTAB 75:PRINT"   0" 

15190 GOTO 60

15200 BB=0:VTAB 21:HTAB 75:PRINT"    "
15202 FOR I=1 TO 39
15210 FOR J=1 TO 39
15220 IF B(I,J)=1 THEN COLOR=1:PLOT I,J:BB=BB+1:GOSUB 1200
15222 IF B(I,J)<>1 THEN COLOR=0:PLOT I,J
15230 NEXT J
15240 NEXT I
15250 RETURN

15500 NORMAL:VTAB 21:HTAB 44:PRINT"                "

15502 FOR I=1 TO 39
15510 FOR J=1 TO 39
15520 COLOR=0:PLOT I,J
15530 NEXT J
15540 NEXT I

15542 FOR I=0 TO 40
15543 FOR J=0 TO 40
15544 B(I,J)=0
15545 NEXT J
15546 NEXT I

15548 X1=22:Y1=20:COLOR=1:PLOT 22,20:BB=0
15549 VTAB 21:HTAB 75:PRINT"   0":VTAB 22:HTAB 75:PRINT"   0":VTAB 23:HTAB 75:PRINT"   0"

15550 GOTO 60

15800 TEXT:HOME
15802 PRINT
15804 PRINT CHR$(4);"CATALOG"

15810 PRINT:PRINT"<PRESS ANY KEY TO BE CONTINUE>":NORMAL:GET CT$:PRINT CT$
15820 HOME:GR:BB=0
15830 FOR I=1 TO 39
15840 FOR J=1 TO 39
15850 IF B(I,J)=1 THEN COLOR=1:PLOT I,J:BB=BB+1
15860 NEXT J
15870 NEXT I
15880 COLOR=15:PLOT 20,20:COLOR=6:PLOT X1,Y1
15990 GOTO 52


18000 TEXT:HOME:PRINT
18006 GOSUB 20040
18820 HOME:GR:BB=0
18830 FOR I=1 TO 39
18840 FOR J=1 TO 39
18850 IF B(I,J)=1 THEN COLOR=1:PLOT I,J:BB=BB+1
18860 NEXT J
18870 NEXT I
18880 COLOR=15:PLOT 20,20:COLOR=6:PLOT X1,Y1
18990 GOTO 52


20000 PRINT:PRINT:PRINT
20010 PRINT"                               MOUSE & MAZE"
20020 PRINT"                          DESIGNED BY TIMOTHY WEN"
20030 PRINT"                            09/2008 PD SOFTWARE"

20032 PRINT:PRINT:PRINT:PRINT"                       <PRESS ANY KEY TO BE CONTINUE>":NORMAL:GET CT$:PRINT CT$

20040 HOME
20050 PRINT"COMMAND :"
20060 PRINT
20070 PRINT"          I,J,K,M      ADD ELEMENT OF WALL TO BUILD MAZE."
20080 PRINT
20090 PRINT"          Y,G,H,B      DELETE ELEMENT OF WALL TO BUILD MAZE."
20110 PRINT

20112 PRINT"          ^Y,^G,^H,^B  JUST MOVE CURSOR,NO ADDING OR DELETING ELEMENT OF WALL."

20114 PRINT

20120 PRINT"          R            BEGIN TO RUN THE MOUSE."
20150 REM PRINT
20160 PRINT"          Q            QUIT THE PROGRAM."
20170 REM PRINT
20180 PRINT"          S            SAVE MAZE PATTERN."
20190 REM PRINT
20200 PRINT"          L            LOAD MAZE PATTERN."
20210 REM PRINT
20220 PRINT"          C            CLEAR DESIGNING AREA."
20230 REM PRINT
20240 PRINT"          X            SHOW THE SAVED MAZE FILES."

20242 REM PRINT
20244 PRINT"          O            SHOW THE COMMAND HELP PAGE."


20246 REM PRINT
20248 PRINT"          A            RANDOM MAZE GENERATOR."


20250 PRINT:PRINT:PRINT:PRINT"                       <PRESS ANY KEY TO BE CONTINUE>":NORMAL:GET CT$:PRINT CT$
20260 RETURN



22000 VTAB 21:HTAB 1:PRINT"     Y   ":VTAB 21:HTAB 10:PRINT"I    ":VTAB 21:HTAB 15:PRINT"R - RUN   ":VTAB 21:HTAB 25:PRINT"S - SAVE MAZE                            ":VTAB 21:HTAB 66:PRINT" BLOCK :    0  "
22010 VTAB 22:HTAB 1:PRINT"    G H ":VTAB 22:HTAB 9:PRINT"J K             ":VTAB 22:HTAB 25:PRINT"L - LOAD MAZE    ":VTAB 22:HTAB 42:PRINT"X - CATALOG  ":VTAB 22:HTAB 55:PRINT"O - HELP   ":VTAB 22:HTAB 66:PRINT"  STEP :    0  "
22020 VTAB 23:HTAB 1:PRINT"     B   ":VTAB 23:HTAB 10:PRINT"M    ":VTAB 23:HTAB 15:PRINT"Q - QUIT  ":VTAB 23:HTAB 25:PRINT"C - CLEAR SCN    ":VTAB 23:HTAB 42:PRINT"A - RANDOM MAZE         ":VTAB 23:HTAB 66:PRINT"RESTEP :    0 "

22030 RETURN


23000 TEXT:HOME:PRINT:PRINT"ERROR OCCURED":END



29000 IF X1=20 AND Y1=20 THEN 29040
29010 IF B(X1,Y1)=1 THEN COLOR=1:PLOT X1,Y1
29020 IF B(X1,Y1)=0 THEN COLOR=0:PLOT X1,Y1
29030 IF X2=20 AND Y2=20 THEN 29050
29040 COLOR=6:PLOT X2,Y2
 

29050 RETURN



60000 IF A$=CHR$(10) OR A$=CHR$(13) OR A$=CHR$(22) OR A$=CHR$(12) OR A$=CHR$(11) OR A$=CHR$(17) OR A$=CHR$(23) OR A$=CHR$(21) OR A$=CHR$(27) THEN A$=" "
60002 RETURN
   

